package com.sky.mapper;

import com.sky.entity.SetmealDish;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDishMapper {


    /**
     * 根据菜品id查询菜品与套餐是否有关系
     * @param dishId
     * @return
     */
    @Select("select count(1) from setmeal_dish where dish_id = #{dishId}")
    boolean existsByDishId(Long dishId);


    /**
     * 新增套餐(再保存到中间表(setmealDish)) 被修改复用
     * @param setmealDish
     */
    @Insert("insert into setmeal_dish " +
            "values (null,#{setmealId},#{dishId},#{name},#{price},#{copies})")
    void save(SetmealDish setmealDish);


    /**
     *回显套餐(因为要修改) 再查中间表菜品集合
     * @param setmealId
     * @return
     */

    @Select("select * from setmeal_dish where setmeal_id = #{setmealId}")
    List<SetmealDish> findBySetmealId(Long setmealId);


    /**
     * 修改套餐之先根据套餐id删除中间表现有的数据(先删除旧的菜品集合)
     * @param setmealId
     */
    @Delete("delete from setmeal_dish where setmeal_id = #{setmealId}")
    void deleteBySetmealId(Long setmealId);


    /**
     * 根据套餐id查询菜品
     * @param setmealId
     * @return
     */
    @Select("select d.description,d.image,d.name ,sd.copies from dish d inner join setmeal_dish sd " +
            "on d.id = sd.dish_id where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> findDishBySetmealId(Long setmealId);


}
